package com.xy.common.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.xy.core.web.WebErrors;

/**
 * 前台工具类
 * 
 * 
 */
public class FrontUtils {
 
 

	/**
	 * 成功提示页面
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	public static String showSuccess(HttpServletRequest request,
			Map<String, Object> model, String nextUrl) {
		 
		return "/front/common/成功提示页面.html";
	}

	/**
	 * 错误提示页面
	 * 
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	public static String showError(HttpServletRequest request,
			HttpServletResponse response, Map<String, Object> model,
			WebErrors errors) {
		errors.toModel(model);
		return "/front/common/错误提示页面.html";
	}

	/**
	 * 信息提示页面
	 * 
	 * @param request
	 * @param model
	 * @param message
	 *            进行国际化处理
	 * @return
	 */
	public static String showMessage(HttpServletRequest request,
			Map<String, Object> model, String message) {
		model.put("message", message);
		return "/front/common/信息提示页面.html";
	}

	/**
	 * 显示登录页面
	 * 
	 * @param request
	 * @param model
	 * @param site
	 * @param message
	 * @return
	 */
	public static String showLogin(HttpServletRequest request,
			Map<String, Object> model , String message) {
		if (!StringUtils.isBlank(message)) {
			model.put("message", message);
		}
		StringBuilder buff = new StringBuilder("redirect:");
		buff.append("/login.jspx").append("?");
		buff.append("returnUrl").append("=");
		buff.append(RequestUtils.getLocation(request));
		 
		return buff.toString();
	}

	/**
	 * 显示登录页面
	 * 
	 * @param request
	 * @param model
	 * @param site
	 * @return
	 */
	public static String showLogin(HttpServletRequest request,
			Map<String, Object> model ) {
		return showLogin(request, model,   "true");
	}
 
}
